In these exercises we are going to see what the compiler thinks is a sensible C program and how it reacts when our program is not correct.

  1. Start up MPLAB X and create a new project as described earlier in the course.

  2. Add the following code to create an simple C program and compile it.

    /* my first program */
    void main ( void )
    {
    }
  3. Change the main function name to mane and recompile the program. Note what the compiler does and try to understand why it has done this.

  4. Put the name mane back to main and then create a second main function which looks just like the first (you can use block copy for this). Recompile the program and note that the compiler will complain again.

  5. Go back to a single copy of the main file and take the open bracket off the ( void ) parameter list in the main function header.













Answers
  1. You get the error : Failure Couldn't find function/label by name:main. This is because the linker is looking for a main function to start when the program runs, and not finding anything.

  2. You get the error : error: Function 'main' already has a body This is because the compiler can't make sense of there being two different things with the same name.

  3. You get the series of errors: error: missing semicolon error: failure This is because when the compiler sees a single closing bracket, it gets very confused and doesn't know quite what to do.